<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class WechatLoginRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'code' => 'required|string',
            'userInfo' => 'sometimes|array',
            'userInfo.nickName' => 'sometimes|string|max:50',
            'userInfo.avatarUrl' => 'sometimes|string|url',
            'userInfo.phoneNumber' => 'sometimes|string|max:20',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'code.required' => '微信授权码不能为空',
            'userInfo.nickName.max' => '用户昵称不能超过50个字符',
            'userInfo.avatarUrl.url' => '头像URL格式不正确',
            'userInfo.phoneNumber.max' => '手机号不能超过20个字符',
        ];
    }
}
